import sys
import os
import random
import time
BASE_PATH = os.path.dirname(
    os.path.dirname(os.path.abspath(__file__))
)
sys.path.insert(0,BASE_PATH)

from bin import get_Webdriver
from conf import settings
from .login import Login_Action

class Public():
    def __init__(self):
        # self.driver = Pyse("chrome")
        self.driver = get_Webdriver.Get_Webdriver().driver
        # self.driver = Pyse("phantomjs")
        self.userUrl = 'http://192.168.224.39/login.html'
        self.adminUrl = 'http://192.168.224.39/admin/login.html'

    def getMsgTitle(self):
        """获取提示信息标题"""
        return self.driver.get_text("css=>div[i='title']")

    def getMsgContent(self):
        """获取提示信息内容"""
        return self.driver.get_text("css=>div[i='content']")

    def clickOKButton(self):
        """点击提示框确定按钮"""
        self.driver.click("css=>button[i-id='ok']")

    def clickCancelButton(self):
        """点击提示框取消按钮"""
        # self.driver.click("css=>button[i-id='cancle']")
        self.driver.click("css=>div[i='button']>button[i-id='cancel']")

    def refresh(self):
        """点击提示框取消按钮"""
        self.driver.F5()

    def createPhone(self):
        prelist = ["130", "131", "132", "133", "134", "135", "136", "137", "138", "139", "147", "150", "151", "152",
                   "153",
                   "155", "156", "157", "158", "159", "186", "187", "188"]
        return random.choice(prelist) + "".join(random.choice("0123456789") for i in range(8))

    # def get_operationDetails(self):
    #     """待新页面做好"""
    #     self.driver.click("css=>.icon-bell-alt.smallbell")
    #     time.sleep(1)
    #     operationDetails={}
    #     operationDetails["coupon"] = self.driver.get_text("id=>mycoupon").text #点券
    #     operationDetails["apicount"] = self.driver.get_text("id=>apicount").text  # 已请求
    #     operationDetails["downloadcount"] = self.driver.get_text("id=>downloadcount").text  # 已下载
    #     operationDetails["spacecount"] = self.driver.get_text("id=>spacecount").text  # 已用空间
    #     return operationDetails #返回字典

    def clickLogout(self):
        """点击退出登录按钮"""
        self.driver.click("css=>li[class='dropdown meun-user']")
        self.driver.click("css=>a[href='/logout.html']")

    def getinputTextbyId(self, id):
        """获取输入框中输入的值"""
        script = "return $('#{}').val();".format(id)
        input_value = self.driver.js_getvalue(script)
        return input_value

    def getCurrentUrl(self):
        url = self.driver.get_url()
        return url

    def setupLogin(self):
        '''在不同环境测试修改这里'''
        loginInfo = settings.loginIfo
        Login_Action().login(telphoneOrMail=loginInfo[0], checkCode=loginInfo[1], token=loginInfo[2])
        # Login_Action().login(telphoneOrMail="18888888889", checkCode='000000')

    def setupLoginPage(self):
        '''在不同环境测试修改这里'''
        Login_Action().jumnptoLoginpage()
        # Login_Action().jumnptoLoginpage(siteType='alpha')
